package cn.bdqn.controller.reportForms;

import cn.bdqn.dao.reportForms.UserRegisterMapper;
import cn.bdqn.pojo.reportForms.UserRegisterReportForms;
import cn.bdqn.service.reportForms.UserReportFormsService;
import cn.bdqn.utils.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;


@RestController
@RequestMapping("/api/reportForms")
public class UserReportFormsController {
    @Autowired
    private UserReportFormsService userReportFormsService;

    @GetMapping("/userRegister")
    public Json getUserRegister(){

        List<UserRegisterReportForms> userRegisterReportFormsByOnMouth =
                userReportFormsService.getUserRegisterReportFormsByOnMouth();
//        UserRegisterReportForms maxByOnMouth = userReportFormsService.getMaxByOnMouth();
        if (Objects.isNull(userRegisterReportFormsByOnMouth)) {
            return Json.fall("查询失败");
        }
        HashMap<String, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("list",userRegisterReportFormsByOnMouth);
//        objectObjectHashMap.put("max",maxByOnMouth.getMax());
//        objectObjectHashMap.put("min",maxByOnMouth.getMin());
        return Json.ok(objectObjectHashMap);
    }
    @GetMapping("/getUserRegisterLastMonth")
    public Json getUserRegisterLastMonth(){
        List<UserRegisterReportForms> userRegisterReportFormsList =
                userReportFormsService.getUserRegisterReportFormsByLastOnMouth();
//        UserRegisterReportForms maxandMInLastMouth = userReportFormsService.getMaxandMInLastMouth();

        if (Objects.isNull(userRegisterReportFormsList)){
            return Json.fall("查询失败");
        }
        HashMap<String, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("list",userRegisterReportFormsList);
//        objectObjectHashMap.put("max",maxandMInLastMouth.getMax());
//        objectObjectHashMap.put("min",maxandMInLastMouth.getMin());
        return Json.ok(objectObjectHashMap);
    }

    //查询近7天的用户注册数量
    @GetMapping("/Nearly7Days")
    public Json Nearly7Days(String start,String end){
        List<UserRegisterReportForms> count = userReportFormsService.Nearly7Days(start==null?null:start+" 00:00:00",end==null?null:end+" 23:59:59");
        Json json=new Json();
        json.setData(count);
        return json;
    }

//    @GetMapping("/toDaySalesVolume")
//    public Json getToDaySalesVolume(){
//
//    }


}
